service command
service
- run a System V init script
The service
command in Linux is a utility used to manage system services (e.g., start, stop, restart, or check the status of daemons like web servers or databases). It’s commonly used on systems with SysVinit or as a compatibility layer for older scripts on systemd-based systems.
Note: On modern systems using systemd
, systemctl
is the preferred tool, but service
often works as a wrapper for backward compatibility.
Usage: service [service_name] [action]
service_name
: The name of the service (e.g., apache2, ssh).action
: The command to perform (e.g., start, stop, restart).
Examples
-
Basic Usage
Run
service
with a service name and an action to control it.service ssh start
- Starts the SSH service (often named
sshd
orssh
depending on the system). - Requires root privileges—use
sudo
if not root:sudo service ssh start
- Starts the SSH service (often named
-
Common Actions
Here are the typical actions you can perform:
Action Description start
Start the service stop
Stop the service restart
Stop and then start the service reload
Reload configuration without stopping status
Check the service’s current state - Stop a service:
sudo service apache2 stop
- Restart a service:
sudo service nginx restart
- Check status:
sudo service ssh status
- Output might vary (e.g.,
[ ok ] sshd is running
or systemd-style details).
- Output might vary (e.g.,
- Stop a service:
-
Listing All Services
Use
service
with--status-all
to see the status of all services (SysVinit only).service --status-all
- Output (example):
[ + ] apache2
[ - ] bluetooth
[ ? ] cron +
: Running,-
: Stopped,?
: Unknown or no status script.
Note: This doesn’t work reliably on systemd systems—use
systemctl list-units
instead. - Output (example):
-
Reloading Configuration
Use
reload
to apply changes without interrupting the service (if supported).sudo service nginx reload
- Reloads
nginx
configuration without dropping connections.
- Reloads
-
Using with Systemd
On systemd systems,
service
redirects tosystemctl
under the hood.sudo service sshd restart
- Equivalent to
sudo systemctl restart sshd
. - Output might show systemd messages (e.g.,
Active: active (running)
).
- Equivalent to
To get help related to the service
command use --help
option
$ service --help
Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]
For more details, check the manual with man service